package com.bwie.utils;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Title:
 * @BelongProjecet month0617
 * @BelongPackage com.bwie.utils
 * @Description:
 * @Copyright 研发一部
 * @Author: Mr.yan
 * @Date: 2024/6/17 17:18
 * @Version V1.0
 */
@Configuration
public class RabbitConfig {
    /***
     * @Description: //创建队列
     * @Auther: yanxingru
     * @Date: 2024/6/17 17:20
     * @param:
     * @return org.springframework.amqp.core.Queue
     */
    @Bean
    public Queue freeMakerQueue(){
        //1.第一个参数是队列名称
        //2.第二个参数是开启持久化，防止数据丢失
        return new Queue("freeMakerQueue",true);
    }

    /**
     * @Description: //创建交换机
     * @Auther: yanxingru
     * @Date: 2024/6/17 17:20
     * @param:
     * @return org.springframework.amqp.core.DirectExchange
     */
    @Bean
    public DirectExchange directExchange(){
        //创建交换机
        return new DirectExchange("directExchange");
    }

    /**
     * @Description: //使交换机和队列绑定
     * @Auther: yanxingru
     * @Date: 2024/6/17 17:20
     * @param:
     * @return org.springframework.amqp.core.Binding;
     */
    @Bean
    public Binding freeBind(){
        //创建交换机
        return BindingBuilder.bind(freeMakerQueue()).to(directExchange()).with("freeBind");
    }

}
